<template>
  <div>
    <input type="text" placeholder="账号" v-model="username">
    <input type="text" placeholder="密码" v-model="password">
    <button @click="appLogin()">登录</button>
  </div>
</template>

<script>
  import {commonAjax} from '../api/api'
  import md5 from 'md5'
  export default {
    data() {
      return {
        username: '18012345678',
        password: 'qwe123',
        // =============
        // username: 'cls',
        // password: 'jzh1911',
        // =============
      }
    },
    mounted() {

    },
    methods: {
      appLogin () {
        if (!this.password || !this.username) {
          return
        }
        let param = {
          orgid: '',
          password: md5(this.password),
          username: this.username,
          utype: '1'
        }
        commonAjax('login', param).then(res => {
          if (res.data.code == 200) {
            let param = res.data.data
            sessionStorage.setItem('sn', param.sn)
            sessionStorage.setItem('token', param.token)
            sessionStorage.setItem('userId', param.id)
            sessionStorage.setItem('device', 'aaa')
            sessionStorage.setItem('hospitalCode', param.code)
            this.$router.push('/index')
          } else {
            alert(res.data.message)
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
